#include "brpc.pb.h"
#include <brpc/server.h>
#include <butil/logging.h>
//https://blog.csdn.net/m0_73987904/article/details/147156325?spm=1011.2415.3001.5331
//博客同步更新
namespace example
{
    class EchoServiceImpl : public EchoService
    {
    public:
        EchoServiceImpl(){}
        ~EchoServiceImpl(){}
        virtual void Echo(google::protobuf::RpcController* ctl_base,
                          const example::EchoRequest* request,
                          example::EchoResphone* resphone,
                          google::protobuf::Closure* done)
        {
            //brpc::ClosureGuard rpc_guard(done);
            //brpc::Controller* ctl = static_cast<brpc::Controller*>(ctl_base);
            done->Run();
            std::cout<<"accept message: "<<request->message()<<std::endl;
            std::string str = request->message();
            resphone->set_message(str);
        }
    };
}

int main()
{
    logging::LoggingSettings settings;
    settings.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(settings);

    brpc::Server server;
    example::EchoServiceImpl echo_service_impl;

    server.AddService(&echo_service_impl,brpc::ServiceOwnership::SERVER_DOESNT_OWN_SERVICE);

    // butil::EndPoint web_point(butil::IP_ANY,8989);

    brpc::ServerOptions options;
    options.idle_timeout_sec = 10;

    server.Start(8989,&options);

    server.RunUntilAskedToQuit();
    return 0;
}
